var a = require("../../@babel/runtime/helpers/defineProperty"),
  t = require("../../res/www.a9a.cn.js"),
  e = getApp(),
  n = wx.getStorageSync("COOK_U");
Page({
  data: {
    currentTab: "sx",
    detail_flag: !1,
    mask_class: "alpha0_100",
    div_login: !1,
    iflogin: !1,
    ifonload: !1,
    ifsubscribe: !1,
    subscribebox: !1,
  },
  topbarFn: function (a) {
    if (this.data.iflogin) {
      var t = a.currentTarget.dataset.var;
      "tz" == t
        ? (this.setData({ currentTab: t }), this.get_data("tz"))
        : "hh" == t
        ? wx.navigateTo({ url: "../my/hh?t=2" })
        : "fk" == t
        ? wx.navigateTo({ url: "../my/browse?t=1" })
        : (this.setData({ currentTab: t }), this.get_data("chat"));
    } else this.setData({ iflogin: !1 });
  },
  onLoad: function () {
    var a = this,
      n = this;
    e.get_config("_ZEAI").then(function (a) {
      n.setData({ color: a.color, rgbcolor: t.c16_rgb(a.color) });
    }),
      e.chklogin().then(function (t) {
        t
          ? (a.get_data("def"),
            n.setData({ iflogin: !0, div_login: !1, ifonload: !0 }))
          : n.setData({ iflogin: !1, ifonload: !0 });
      });
  },
  get_data: function (a) {
    var i = this;
    (n = wx.getStorageSync("COOK_U")),
      wx.showLoading({ title: "玩命加载中", mask: !0 }),
      e.ajax({
        url: "my_msg.php",
        data: { submitok: a, openid: n.openid },
        success: function (e) {
          if (1 == e.flag) {
            var n = t.get_tabbar_index("my_msg");
            e.btmnewnum.allnum > 0
              ? wx.setTabBarBadge({ index: n, text: e.btmnewnum.allnum })
              : wx.removeTabBarBadge({ index: n });
            var s = 1 == e.subscribe;
            "def" == a &&
              ((a = e.msg_nav.def), i.setData({ currentTab: e.msg_nav.def })),
              "tz" == a
                ? i.setData({
                    TZ: e.TZ,
                    MB: e.MB,
                    ifsubscribe: s,
                    wx_gzh_ewm: e.wx_gzh_ewm,
                    btmnewnum: e.btmnewnum,
                    msg_nav: e.msg_nav,
                  })
                : i.setData({
                    CHAT: e.CHAT,
                    MB: e.MB,
                    ifsubscribe: s,
                    wx_gzh_ewm: e.wx_gzh_ewm,
                    btmnewnum: e.btmnewnum,
                    msg_nav: e.msg_nav,
                  });
          } else i.setData({ CHAT: [] });
          wx.hideLoading();
        },
      });
  },
  detailFn: function (i) {
    var s = this;
    t.empty(s.data.MB) || e.openSetting(s.data.MB);
    var o = i.currentTarget.dataset.id,
      r = i.currentTarget.dataset.idx;
    (n = wx.getStorageSync("COOK_U")),
      1 == s.data.TZ[r].new
        ? e.ajax({
            url: "my_msg.php",
            data: { submitok: "detail", id: o, openid: n.openid },
            success: function (e) {
              if (1 == e.flag) {
                var n,
                  i = t.get_tabbar_index("my_msg"),
                  o = parseInt(s.data.btmnewnum.allnum),
                  c = parseInt(s.data.btmnewnum.tznum);
                1 == s.data.TZ[r].new &&
                  (--o < 0 && (o = 0), --c < 0 && (c = 0)),
                  s.setData(
                    ((n = {
                      detail: !0,
                      mask_class: "alpha0_100",
                      detail_title: s.data.TZ[r].title,
                      detail_content: s.data.TZ[r].content,
                    }),
                    a(n, "TZ[" + r + "].new", 0),
                    a(n, "btmnewnum.allnum", o),
                    a(n, "btmnewnum.tznum", c),
                    n)
                  ),
                  o > 0
                    ? wx.setTabBarBadge({ index: i, text: "" + o })
                    : wx.removeTabBarBadge({ index: i });
              } else wx.showToast({ title: e.msg, icon: "none", mask: !0 });
            },
          })
        : s.setData(
            a(
              {
                detail: !0,
                mask_class: "alpha0_100",
                detail_title: s.data.TZ[r].title,
                detail_content: s.data.TZ[r].content,
              },
              "TZ[" + r + "].new",
              0
            )
          );
  },
  mask_closeFn: function (t) {
    var e = this,
      n = t.currentTarget.dataset.maskid;
    this.setData({ mask_class: "alpha100_0" }),
      setTimeout(function () {
        e.setData(a({}, n, !1));
      }, 500);
  },
  emptyFn: function () {},
  back: function () {
    this.setData({ div_login: !1 });
  },
  onShow: function () {
    if (this.data.ifonload) {
      var a = this;
      e.chklogin().then(function (t) {
        t
          ? (a.get_data("chat"), a.setData({ iflogin: !0, div_login: !1 }))
          : a.setData({ iflogin: !1, div_login: !1 });
      });
    }
  },
  lawFn: function (a) {
    var t = a.currentTarget.dataset.kind;
    wx.navigateTo({ url: "/pages/about/law?kind=" + t });
  },
  subscribeFn: function () {
    this.setData({ subscribebox: !0, mask_class: "alpha0_100" });
  },
  getPhoneNumber: function (a) {
    wx.login({
      success: function (i) {
        wx.request({
          url: e.WWW + "/api/wxxcx/get_openid.php",
          data: { code: i.code },
          success: function (i) {
            (i = t.jsoneval(i.data)),
              (n = wx.getStorageSync("COOK_U")),
              wx.request({
                url: e.WWW + "/api/wxxcx/get_mob.php",
                data: {
                  session_key: encodeURIComponent(i.U.session_key),
                  encryptedData: encodeURIComponent(a.detail.encryptedData),
                  iv: encodeURIComponent(a.detail.iv),
                  openid: i.U.openid,
                },
                success: function (a) {
                  (a = t.jsoneval(a.data)), wx.reLaunch({ url: "../my/my" });
                },
                fail: function (a) {
                  wx.showModal({ content: a, showCancel: !1 });
                },
              });
          },
        });
      },
    });
  },
  ifagreeFn: function (a) {
    1 == a.detail.value
      ? this.setData({ ifagree: !0 })
      : this.setData({ ifagree: !1 });
  },
  ifagree_passFn: function () {
    wx.showToast({
      title: "请先点击同意《用户协议》和《隐私条款》",
      icon: "none",
      mask: !0,
      duration: 3e3,
    });
  },
  privacy_agree: function (a) {
    console.log("agree");
  },
  privacy_disagree: function (a) {
    console.log("disagree"), wx.exitMiniProgram();
  },
});
